//
//  HTIndexViewController.m
//  HeartTravel
//
//  Created by lanou on 15/10/24.
//  Copyright © 2015年 陈文杰. All rights reserved.
//

#import "HTIndexViewController.h"
#import "HTTripViewController.h"
#import "HTMusicViewController.h"
#import "HTVideoTableViewController.h"
#import "HTWishViewController.h"

#define Space (SCREEN_WIDTH-200)/5

@interface HTIndexViewController ()

@property (nonatomic, strong) UIView *catalogueView;
@property (nonatomic, strong) UIView *buttonLine;
@property (nonatomic, strong) UIButton *tripButton;
@property (nonatomic, strong) UIButton *videoButton;
@property (nonatomic, strong) UIButton *musicButton;
@property (nonatomic, strong) UIButton *wishButton;

@property (nonatomic, strong) HTTripViewController *tripVC;
@property (nonatomic, strong) HTMusicViewController *musicVC;
@property (nonatomic, strong) HTWishViewController *wishVC;
@property (nonatomic, strong) HTVideoTableViewController *videoVC;

@end

@implementation HTIndexViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.hidden = YES;
    self.titleLabel.text = @"首页";
//    [self.rightButton setBackgroundImage:[UIImage imageNamed:@"搜索"] forState:(UIControlStateNormal)];
    
    [self p_setupCatalogueView];
    
    _wishVC = [[HTWishViewController alloc] init];
    _wishVC.view.frame = CGRectMake(0, 110, SCREEN_WIDTH, SCREEN_HEIGHT-150);
    [self.view addSubview:_wishVC.view];
    
    _musicVC = [[HTMusicViewController alloc] init];
    _musicVC.view.frame = CGRectMake(0, 110, SCREEN_WIDTH, SCREEN_HEIGHT-150);
    [self.view addSubview:_musicVC.view];
    [self addChildViewController:_musicVC];
    
    _videoVC = [[HTVideoTableViewController alloc] init];
    _videoVC.videoVC = self.navigationController;
    _videoVC.VC = self;
    _videoVC.view.frame = CGRectMake(0, 110, SCREEN_WIDTH, SCREEN_HEIGHT-150);
    [self.view addSubview:_videoVC.view];
    
    _tripVC = [[HTTripViewController alloc] init];
    _tripVC.view.frame = CGRectMake(0, 110, SCREEN_WIDTH, SCREEN_HEIGHT-150);
    _tripVC.navigationController = self.navigationController;
    [self.view addSubview:_tripVC.view];
}

- (void)p_setupCatalogueView {
    
    _catalogueView = [[UIView alloc] initWithFrame:CGRectMake(0, 70, SCREEN_WIDTH, 40)];
    
    _tripButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    _tripButton.frame = CGRectMake(Space, 5, 50, 30);
    [_tripButton setTitle:@"践行" forState:(UIControlStateNormal)];
    [_tripButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [_tripButton addTarget:self action:@selector(handleTripButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [_catalogueView addSubview:_tripButton];
    
    _videoButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    _videoButton.frame = CGRectMake(Space*2+50, 5, 50, 30);
    [_videoButton setTitle:@"偷闲" forState:(UIControlStateNormal)];
    [_videoButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [_videoButton addTarget:self action:@selector(handleVideoButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [_catalogueView addSubview:_videoButton];
    
    _musicButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    _musicButton.frame = CGRectMake(Space*3+100, 5, 50, 30);
    [_musicButton setTitle:@"慢旅" forState:(UIControlStateNormal)];
    [_musicButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [_musicButton addTarget:self action:@selector(handleMusicButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [_catalogueView addSubview:_musicButton];
    
    _wishButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    _wishButton.frame = CGRectMake(Space*4+150, 5, 50, 30);
    [_wishButton setTitle:@"愿望" forState:(UIControlStateNormal)];
    [_wishButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [_wishButton addTarget:self action:@selector(handleWishButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [_catalogueView addSubview:_wishButton];
    
    _buttonLine = [[UIView alloc] initWithFrame:CGRectMake(Space+10, 37, 30, 3)];
    _buttonLine.backgroundColor = [UIColor blackColor];
    [_catalogueView addSubview:_buttonLine];
    
    UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(0, 39, SCREEN_WIDTH, 1)];
    separator.backgroundColor = [UIColor colorWithWhite:0.810 alpha:1.000];
    [_catalogueView addSubview:separator];
    
    [self.view addSubview:_catalogueView];
}

- (void)handleTripButtonAction:(id)sender {
    [_videoVC.moviePlayerController stop];
    _buttonLine.frame = CGRectMake(Space+10, 37, 30, 3);
    [self.view bringSubviewToFront:_tripVC.view];
}

- (void)handleVideoButtonAction:(id)sender {
    _buttonLine.frame = CGRectMake(Space*2+60, 37, 30, 3);
    [self.view bringSubviewToFront:_videoVC.view];
}

- (void)handleMusicButtonAction:(id)sender {
    [_videoVC.moviePlayerController stop];
    _buttonLine.frame = CGRectMake(Space*3+110, 37, 30, 3);
    [self.view bringSubviewToFront:_musicVC.view];
}

- (void)handleWishButtonAction:(id)sender {
    [_videoVC.moviePlayerController stop];
    _buttonLine.frame = CGRectMake(Space*4+160, 37, 30, 3);
    [self.view bringSubviewToFront:_wishVC.view];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
